#pragma once

#include "form/IControlBars.h"

class ControlBars: public IControlBars
{
	typedef std::map<String,sys::ObjectPtr> ToolBarDictionary;
	typedef std::map<uint32,IObject*> CommandMap;
	static String ToolboxName;

public:
	BEGIN_DEFINE_CLASS(CLSID_ControlBars)
		DEFINE_INTERFACE_ENTRY(IControlBars)
	END_DEFINE_CLASS()

	ControlBars();
	virtual ~ControlBars();

	virtual IMenuBar* GetMenuBar() const;
	virtual IToolBar* GetToolbox() const;
	virtual IToolBar* AddToolbar(const String& name,int32 align);
	virtual IToolBar* FindToolbar(const String& name);
	virtual bool ContainControl(uint32 id) const;
	virtual IObject* FindControl(uint32 id) const;

	bool RegisterControl(IObject* control);

protected:
	virtual uint32 GetToolbars(ToolbarList& toolbars) const;

private:
	uint32 FindFreeCommandID() const;
	uint32 FindRegisteredGlobalCommandID(IObject* control);
	mutable sys::ObjectPtr m_toolbox;
	mutable sys::ObjectPtr m_menuBar;
	ToolBarDictionary m_controlbars;
	CommandMap m_mapCommands;
};
AUTO_REGISTER_CLASSMAP_ENTRY(ControlBars)

#ifndef ID_RESERVEID_FIRST
#define ID_RESERVEID_FIRST	48001
#endif

#ifndef ID_RESERVEID_LAST
#define ID_RESERVEID_LAST	49000
#endif

#ifndef IS_COMMAND_RESERVER
#define IS_COMMAND_RESERVER(cmd) ((cmd>=ID_RESERVEID_FIRST)&&(cmd<=ID_RESERVEID_LAST))
#endif